<?php
declare (strict_types=1);

namespace app\admin\model\iot;

use app\admin\model\base\User;
use app\BaseModel;

/**
 * 全部出袋记录表模型
 */
class ScanBagOrder extends BaseModel
{

    /**
     * 获取出袋记录列表
     * @param array $where
     * @param int $page
     * @param int $limit
     * @param string $orderby
     * @param string $field
     * @return array
     */
    public static function getList(array $where, int $page, int $limit, string $orderby = '', string $field = '*'): array
    {
        //查询
        $data = self::alias('a')
            ->field($field)
            ->where($where)
            ->join((new User())->getTable() . ' b', 'a.user_id = b.id')
            ->order($orderby)
            ->paginate(['list_rows' => $limit, 'page' => $page], false)
            ->toArray();
        return $data;
    }

    /**
     * 写入出袋日志
     * @param array $order_data
     * @return bool
     */
    public static function writeOutBagOrder(array $order_data): bool
    {
        $model = new self();
        $array = ['order_state' => '出袋失败', 'create_time' => time()];
        $order_data = array_merge($order_data, $array);
        return $model->save($order_data);
    }

}




